package com.lzy.cloud.order.controller;

import com.lzy.cloud.order.dtos.OrderAppealPicDto;
import com.lzy.cloud.order.request.OrderAppealPicRequest;
import com.lzy.cloud.order.response.OrderAppealPicResponse;
import com.lzy.cloud.order.service.OrderAppealPicService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消费者订单投诉的图片信息
 * Created by WIN7 on 2018/6/6.
 */
@RestController
@RequestMapping("/order/appeal/pic")
public class OrderAppealPicController {

    @Autowired
    private OrderAppealPicService orderAppealPicService;

    /**
     * 根据投诉id查询消费者订单投诉的图片信息
     * @param appealId
     * @return
     */
    @RequestMapping(value = "/find/by/appeal/id/{appealId}",method = RequestMethod.GET)
    public Result queryListByAppealId(@PathVariable("appealId") Long appealId) {
        Ensure.that(appealId).isNotNull("00010003");
        List<OrderAppealPicDto> list = orderAppealPicService.queryListByAppealId(appealId);
        return new Result(DozerUtils.map(list, OrderAppealPicResponse.class));
    }

    /**
     * 新增消费者订单投诉的图片信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public Result create(@RequestBody OrderAppealPicRequest request) {
        Ensure.that(request).isNotNull("00000002");
        Long id = orderAppealPicService.create(DozerUtils.map(request, OrderAppealPicDto.class));
        Ensure.that(id).isGt(0, "00100001");
        return new Result(id);
    }
}
